#pragma once
#include <map>
#include <string>

using namespace std;

class CmdGroupKey
{
private:
	map<string,string> m_values;
public:
	CmdGroupKey(void);
	~CmdGroupKey(void);

	const map<string,string>& values() const;

	string& operator [] (string index) { return m_values[index]; }
	bool operator==(const CmdGroupKey &other) const {
		if( other.values().size() == this->m_values.size() ) return false;
		for( map<string,string>::const_iterator iter = m_values.begin(); iter != m_values.end(); iter++ )
		{
			map<string,string>::const_iterator iter2 = other.m_values.find( (*iter).first );
			if( (*iter).second.compare( (*iter).second ) != 0 ) return false;
		}
		return true;
	}
	/*! Sorts first by the number of keys and then alphabetically among keys (which depends on map implementation)
	*/
	bool operator<(const CmdGroupKey &other) const {
		if( m_values.size() < other.m_values.size() ) return true;
		if( m_values.size() > other.m_values.size() ) return false;

		for( map<string,string>::const_iterator iter = m_values.begin(); iter != m_values.end(); iter++ )
		{
			map<string,string>::const_iterator iter2 = other.m_values.find( (*iter).first );
			int c = (*iter).second.compare( (*iter2).second );
			if( c < 0 ) return true;
			else if( c > 0 ) return false;
		}
		// they are equal
		return false;
	}
};
